package com.inspur.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.inspur.common.annotation.Log;
import com.inspur.common.core.controller.BaseController;
import com.inspur.common.core.domain.AjaxResult;
import com.inspur.common.core.page.TableDataInfo;
import com.inspur.common.enums.BusinessType;
import com.inspur.common.utils.StringUtils;
import com.inspur.common.utils.poi.ExcelUtil;
import com.inspur.system.domain.PmServer;
import com.inspur.system.service.IPmServerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 【服务器】Controller
 * 
 * @author ruoyi
 * @date 2024-04-18
 */
@RestController
@RequestMapping("/system/server")
public class PmServerController extends BaseController
{
    @Autowired
    private IPmServerService pmServerService;

    /**
     * 查询【服务器】列表
     */
    @PreAuthorize("@ss.hasPermi('system:server:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmServer pmServer)
    {
        startPage();
        List<PmServer> list = pmServerService.selectPmServerList(pmServer);
        return getDataTable(list);
    }

    /**
     * 模糊查询【服务器】列表
     */
    @PreAuthorize("@ss.hasPermi('system:server:list')")
    @GetMapping("/listLike")
    public TableDataInfo listLike(PmServer pmServer)
    {
        startPage();
        List<PmServer> list = pmServerService.selectPmServerlistLike(pmServer);
        return getDataTable(list);
    }

    /**
     * 导出【服务器】列表
     */
    @PreAuthorize("@ss.hasPermi('system:server:export')")
    @Log(title = "【服务器】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmServer pmServer)
    {
        List<PmServer> list = pmServerService.selectPmServerList(pmServer);
        ExcelUtil<PmServer> util = new ExcelUtil<PmServer>(PmServer.class);
        util.exportExcel(response, list, "【服务器】数据");
    }

    /**
     * 获取【服务器】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:server:query')")
    @GetMapping(value = "/{serNo}")
    public AjaxResult getInfo(@PathVariable("serNo") String serNo)
    {
        return success(pmServerService.selectPmServerBySerNo(serNo));
    }

    /**
     * 新增【服务器】
     */
    @PreAuthorize("@ss.hasPermi('system:server:add')")
    @Log(title = "【服务器】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmServer pmServer)
    {
        if (StringUtils.isBlank(pmServer.getProNo())){
            return AjaxResult.error("项目编号不能为空！");
        }
        return toAjax(pmServerService.insertPmServer(pmServer));
    }

    /**
     * 修改【服务器】
     */
    @PreAuthorize("@ss.hasPermi('system:server:edit')")
    @Log(title = "【服务器】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmServer pmServer)
    {

        return toAjax(pmServerService.updatePmServer(pmServer));
    }

    /**
     * 删除【服务器】
     */
    @PreAuthorize("@ss.hasPermi('system:server:remove')")
    @Log(title = "【服务器】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{serNos}")
    public AjaxResult remove(@PathVariable String[] serNos)
    {
        return toAjax(pmServerService.deletePmServerBySerNos(serNos));
    }
}
